package com.decent.web.system.dao;

import com.decent.web.system.dao.provider.SystemBrandDaoProvider;
import com.decent.web.system.dto.SystemBrandDTO;
import com.decent.web.system.vo.SystemBrandVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: decent Gjh
 * @date: 2022/10/25/19:01
 * @description:
 */
@Mapper
public interface SystemBrandDao {

    /**
     * 查询品牌
     * @param brandDTO 品牌信息
     * @return 品牌列表
     */
    @SelectProvider(type = SystemBrandDaoProvider.class, method = "list")
    List<SystemBrandVO> selectBrand(@Param("brand") SystemBrandDTO brandDTO);


    /**
     * 根据品牌id获取分类id
     * @param brandId 品牌id
     * @return 分类id
     */
    @Select("select classify_id from common_brand where id = #{brandId}")
    Integer selectClassifyIdByBrandId(@Param("brandId") int brandId);

    /**
     * 获取热门品牌
     * @return 热门品牌列表
     */
    @Select("SELECT id,name,classify_id,sort FROM common_brand brand LEFT JOIN ( " +
            "SELECT sum(sales) s,brand_id FROM common_goods GROUP BY brand_id " +
            ") as good on good.brand_id = brand.id WHERE sort>=0 ORDER BY good.s DESC LIMIT 5 ")
    List<SystemBrandVO> getHot();

    /**
     * 根据id获取品牌名称
     * @param id 品牌id
     * @return 品牌名称
     */
    @Select("select name from common_brand where id = #{id}")
    String getBrandName(@Param("id") Integer id);
}
